package designprinciples.singleresponsibility;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

/**
 * @program: MyTank
 * @description: 统计文件中的单词
 * @author: 王术平
 * @create: 2021-01-23 16:36
 **/
public class NegativeExample {
    public static void main(String[] args) throws IOException {
        //加载文件
        BufferedReader reader = new BufferedReader(new FileReader("D:\\架构师养成记\\Code\\MyTank\\src\\main\\java\\designprinciples\\singleresponsibility\\1.txt"));
        //读取文件，加入到StringBuilder中
        StringBuilder sb = new StringBuilder();
        for (String line = null; (line = reader.readLine()) != null; ) {
            sb.append(line + " \n");
        }
        //切割文件，统计单词数量
        String[] split = sb.toString().split("[^a-zA-Z]+");
        System.out.println("该文件共有" + split.length + "个单词");
        if (reader != null) reader.close();
    }
}
